# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Batch-Simple.t'

#########################

# change 'tests => 1' to 'tests => last_test_to_print';

use warnings;
use strict;
my $totaltest;
BEGIN{ $totaltest = 15;}
use Test::More tests => $totaltest;
BEGIN { use_ok('Batch::Simple')  };

#########################
SKIP: {
	skip 	'Sistema operativo no es Linux',	$totaltest-1		unless $^O =~ /nix$|nux$/;
{
  my $x = Batch::Simple->new(command => q{echo 'hola'});
  my $r = $x->run;
  my $expected = Batch::Simple::Result->new( 'status' => 0, 'stderr' => '', 'stdout' => "hola\n");
  is_deeply($r, $expected, q{execution of 'echo'});
  is("$r", "hola\n", 'toString overloading works');
}

{
  my $x = Batch::Simple->new(command => q{echo}, options => [qw{hola  juan}]);
  my $r = $x->run;
  my $expected = Batch::Simple::Result->new( 'status' => 0, 'stderr' => '', 'stdout' => "hola juan\n");
  is_deeply($r, $expected, q{execution of 'echo' with options});
}

{
  my $x = Batch::Simple->new(q{echo 'hola'});
  my $r = $x->run;
  my $expected = Batch::Simple::Result->new( 'status' => 0, 'stderr' => '', 'stdout' => "hola\n");
  is_deeply($r, $expected, q{Not named call. Execution of 'echo'});

  my $s = 0;
  if ($r) { $s = 1 };
  is($s, 1, 'Overloading to bool works');
}

{
  my $x = Batch::Simple->new(q{/notexist 'hola'});
  my $r = $x->run;

  ok($r->status > 0, q{Command does not exist. Positive status});
  ok(length($r->stderr) > 0, q{Command does not exist. Error message in stderr'});
  ok(length($r->stdout) == 0, q{Command does not exist. Nothing in stdout'});

  my $s = 0;
  if ($r) { $s = 1 };
  is($s, 0, 'Overloading to bool works');

}

{
  my $x = Batch::Simple->new(q{notexist});
  my $r = $x->run;

  ok($r->status == -1, q{Command does not exist. -1 status});
  ok(length($r->stderr) == 0, q{Command does not exist. No error message in stderr'});
  ok(length($r->stdout) == 0, q{Command does not exist. Nothing in stdout'});
}

{
  my $x = Batch::Simple->new(command => q{echo 'hola juan' > tutu});
  my $r = $x->run;
  my $expected = Batch::Simple::Result->new( 'status' => 0, 'stderr' => '', 'stdout' => '');
  is_deeply($r, $expected, q{execution of redirected 'echo'});
}
{
  my $x = Batch::Simple->new(command => q{sort}, input => q{t/prueba.txt});
  my $r = $x->run;
  my $expected = Batch::Simple::Result->new( 'status' => 0, 'stderr' => '', 'stdout' => << 'EOS');

0
1
2
3
5
6
7
8
9
EOS
  is_deeply($r, $expected, q{testing input attribute});
}
}
